<template>
    <div class="page-body">
        <div id="mapContainer" class="mapContainer"></div>
        <div class="level">地图层级：{{ level }}</div>
        <div class="util-options">
            <div class="option-item">工具</div>
            <div class="option-item" @click="setDefaultCenter">定位</div>
            <div class="option-item">+</div>
            <div class="option-item">-</div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { Map } from "/@/assets/mapUtils/map.ts";
import { defaultOption } from "../assets/mapUtils/mapConstant.ts";

onMounted(() => {
    init();
});
const level = ref(0);

function setLevel() {
    //获取当前地图级别
    level.value = Map.map.getZoom();
}

function init() {
    Map.initMap({
        el: "mapContainer", option: {
           custom:(AMap)=>{
               return{
                   // layers: [new AMap.TileLayer.Satellite()],
                   //开启3D视图,默认为关闭
                   viewMode: '3D',
                   // 地图俯仰角度，有效范围 0 度- 83 度
                   pitch: 0,
                   // 开启地形图
                   // terrain: true,
                   zooms:[defaultOption.zoom,16],
                   // 是否开启地图倾斜交互
                   pitchEnable: true,
               }
           }
        }
    }).then(() => {
        Map.map && Map.map.on("zoomend", setLevel);
        Map.map && Map.map.on("zoomend", setLevel);
    });
}
//设置默认中心点
function setDefaultCenter(){

}
</script>
<style scoped lang="less">
.page-body {
    position: relative;
    width: 100%;
    height: calc(100% - 0px);
}

.mapContainer {
    width: 100%;
    height: 100%;
    flex: 1;
}

.level {
    position: absolute;
    top: 50px;
    left: 400px;
    font-size: 18px;
    color: #fff;
}
.util-options{
    position: absolute;
    top: 50px;
    left: 20px;
    max-height: 29px;
    font-size: 16px;
    color: #fff;
    border: 1px solid #ededed;
    overflow: hidden;
    transition: max-height 0.6s;
    &:hover{
        max-height: 800px;
    }
    .option-item{
        padding: 2px 16px ;
        display: flex;
        justify-content: center;
        align-items: center;
        border-bottom: 1px solid #888888;
        cursor: pointer;
        &:not(:first-child):hover{
            color: #474747;
            background-color: #eceff7;
        }
    }
}
</style>